home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 December / PCWDEC07.iso / Software / Freeware / Windows Desktop Search 3.01 / WindowsDesktopSearch-KB917013-V301-XP-x86-enu.exe / dsksrch.chm / msnpanehelp_script.js < prev    next >
Encoding:
JavaScript  |  2007-01-03  |  14.9 KB  |  643 lines

  1. /**********************************************************************
  2.     Javascript functions for Pane Help
  3.     Author: Chris Sanders (csand), 1999-2003
  4.     
  5.     Note: Many functions are designed for PROC, PH_MEGA, TROU topics
  6.     which have subtopic_choice radio buttons.
  7.     
  8.     Note: All functions are designed to work for IE4+ and Nav6 browsers.
  9.     
  10.     Note: Cannot use less-than or greater-than symbols
  11.     in the javascript or the XML parser will crash.
  12. **********************************************************************/
  13.  
  14. // Global variables
  15. var g_strSubtopicChoiceContext = ""
  16. var g_strCurrentContext = ""
  17. var g_arrContextElements
  18. var g_arrContextRelatedElements
  19. var g_arrArrowImages = new Array('arrowblueright.gif','arrowbluedown.gif')
  20.  
  21. var g_arrV4
  22.  
  23. var isIE4 = false
  24. var isNav4 = false
  25. var isNav6 = false
  26.  
  27. //Create the getV4 function, and then run it.
  28. function getV4()
  29. {
  30.     if ( typeof parent.v4 == 'string' )
  31.     {
  32.         var pv4 = parent.v4;
  33.         g_arrV4 = pv4.split(',');
  34.     }
  35.     else
  36.     {
  37.         g_arrV4 = new Array('');
  38.     }
  39. }
  40. getV4(); //execute the function during page load
  41.  
  42. //Conditional content test
  43. function ccTest( strValue )
  44. {
  45.     return ( v4Contains(strValue) || userAgentContains(strValue) );
  46. }
  47.  
  48. function v4Contains( strValue )
  49. {
  50.     if ( typeof strValue == 'string' )
  51.     {
  52.         if ( strValue != "" )
  53.         {
  54.             //Handle possible multiple values
  55.             var arrValues;
  56.             arrValues = strValue.split(',');
  57.             
  58.             for( i = 0; i < g_arrV4.length; i++ )
  59.             {
  60.                 for( j = 0; j < arrValues.length; j++ )
  61.                 {
  62.                     if ( g_arrV4[i] == arrValues[j] ) return true;
  63.                 }
  64.             }
  65.         }
  66.     }    
  67.     return false;
  68. }
  69.  
  70. function userAgentContains( strValue )
  71. {
  72.     if ( typeof strValue == 'string' )
  73.     {
  74.         if ( strValue != "" )
  75.         {
  76.             //Handle possible multiple values
  77.             var arrValues;
  78.             arrValues = strValue.split(',');
  79.             
  80.             for( j = 0; j < arrValues.length; j++ )
  81.             {
  82.                 if ( navigator.userAgent.indexOf( arrValues[j] ) != -1) return true;
  83.             }
  84.         }
  85.     }    
  86.     return false;
  87. }
  88.  
  89. function onPageLoad( strTemplate )
  90. {
  91.     //Even though the page is supposed to be fully loaded before the onLoad event is triggered,
  92.     //Nav6 will return false from the existsForm function unless there is a slight delay before
  93.     //querying for the existence of the form.
  94.     if (isIE4)
  95.     {
  96.         startPage(strTemplate)
  97.     }
  98.     else if (isNav6) 
  99.     {
  100.         var strNext = "startPage('" + strTemplate + "')"
  101.         setTimeout(strNext,0) //Even though the delay is set to 0, this works?!
  102.     }
  103. }
  104.  
  105. function startPage( strTemplate )
  106. {
  107.     if ((strTemplate == 'PROC') || (strTemplate == 'TROU') || (strTemplate == 'PH_MEGA'))
  108.     {
  109.         if ( existsForm("SubtopicChoiceForm") )
  110.         {
  111.             // set the classNames of the elements that have context
  112.             // or are related ancestors of the context elements
  113.             g_arrContextElements = new Array('INSTRUCTIONS','MORE_INFO','LINK')
  114.             g_arrContextRelatedElements = new Array('LINKS')
  115.  
  116.             hideContextContent() //hide any elements that have context
  117.             resetSubtopicChoiceForm() //make sure the buttons are unchecked and the context is nothing
  118.         }
  119.         else
  120.         {
  121.             showContextContent()
  122.         }
  123.     }    
  124. }
  125. function resetSubtopicChoiceForm()
  126. {
  127.      if ( existsForm("SubtopicChoiceForm") )
  128.      {
  129.          //uncheck all SubtopicChoice radio elements
  130.          var oRadioGroup = document.forms["SubtopicChoiceForm"].SubtopicChoice
  131.          for (var i = 0; i < oRadioGroup.length; i++)
  132.          {
  133.              oRadioGroup[i].checked = false
  134.          }
  135.          //set the subtopic_choice context to nothing
  136.          setSubtopicChoiceContext("")
  137.      }
  138. }
  139.  
  140. function setCurrentContext()
  141. {
  142.     g_strCurrentContext = getSubtopicChoiceContext()
  143. }
  144.  
  145. function setSubtopicChoiceContext( strContext )
  146. {
  147.     g_strSubtopicChoiceContext = strContext
  148. }
  149.  
  150. function getSubtopicChoiceContext()
  151. {
  152.     return g_strSubtopicChoiceContext
  153. }
  154.  
  155. function hasTheContext( strElementContext, strCurrentContext )
  156. {
  157.     // Does this element have the current context
  158.  
  159.     var arrElementContext = strElementContext.split(",")
  160.     
  161.     for (var i = 0; i < arrElementContext.length; i++)
  162.     {
  163.         if ( (arrElementContext[i] == g_strCurrentContext) )
  164.         {
  165.             return true
  166.         }
  167.     }
  168.     return false
  169. }
  170. function getElementContext( oElement )
  171. {
  172.     //The context is contained in the id attribute
  173.     var strContext = ( oElement.id ) ? oElement.id : ""
  174.     return strContext
  175. }
  176. function clickedSubtopicChoice( strContext )
  177. {
  178.     setSubtopicChoiceContext( strContext ) // remember the context
  179.     hideContextContent()  // first, hide all context content
  180.     showContextContent()  // finally, show all context content dependent on the new context
  181. }
  182. function clickedSubtopicChoiceText( strContext, strID )
  183. {
  184.     oSubtopicChoice = getElementById( strID );
  185.     oSubtopicChoice.checked = true;
  186.     clickedSubtopicChoice( strContext );
  187. }
  188. function isContextElement( oElement )
  189. {
  190.     // Is oElement an element that uses the id attribute to indicate the context?
  191.     for (var i=0; i < g_arrContextElements.length; i++)
  192.     {
  193.         if (oElement.className == g_arrContextElements[i])
  194.         {
  195.             return true
  196.         }
  197.     }
  198.     return false
  199. }
  200. function isContextRelatedElement( oElement )
  201. {
  202.     // Is oElement an element whose display depends on a child elements context?
  203.     for (var i=0; i < g_arrContextRelatedElements.length; i++)
  204.     {
  205.         if (oElement.className == g_arrContextRelatedElements[i])
  206.         {
  207.             return true
  208.         }
  209.     }
  210.     return false
  211. }
  212. function showContentForContextElement(oElement,oLinksElement)
  213. {
  214.     if (isContextElement(oElement))
  215.     {
  216.         if (hasTheContext(getElementContext(oElement),g_strCurrentContext))
  217.         {
  218.             if (oElement.className == 'LINK')
  219.             {
  220.                 setStylePropertyByElement( oLinksElement, 'display', '' ) // display the related LINKS container
  221.             }
  222.             if (oElement.className == 'SUBTOPIC_CHOICE')
  223.             {
  224.                 var oSubtopicChoicesElement = getElementById('SUBTOPIC_CHOICES')
  225.                 if (oSubtopicChoicesElement != null)
  226.                 {
  227.                     setStylePropertyByElement( oSubtopicChoicesElement, 'display', '' ) // display the related LINKS container
  228.                 }
  229.             }
  230.             setStylePropertyByElement( oElement, 'display', '' ) // display the element
  231.         }
  232.         else
  233.         {
  234.             setStylePropertyByElement( oElement, 'display', 'none' ) // hide the element
  235.         }
  236.     }
  237. }
  238. function showContextContent()
  239. {
  240.     // Display all elements appropriate for the context
  241.     var oElement
  242.     var oLinksElement
  243.     
  244.     //First, make sure that the current context is up-to-date
  245.     setCurrentContext()
  246.     
  247.     if (isIE4)
  248.     {
  249.         for (var i = 0; i != document.all.length; i++)
  250.         {
  251.             oElement = document.all[i]
  252.             if (oElement.className == 'LINKS') 
  253.             {
  254.                 oLinksElement = oElement
  255.             }
  256.             showContentForContextElement(oElement,oLinksElement)
  257.         }
  258.     }
  259.     else if (isNav6)
  260.     {
  261.         var colElements
  262.         //elements with INSTRUCTIONS, MORE_INFO, LINKS className are <div> tags
  263.         colElements = document.getElementsByTagName("div")
  264.         for (var i = 0; i != colElements.length; i++)
  265.         {
  266.             oElement = colElements[i]
  267.             if (oElement.className == 'LINKS') 
  268.             {
  269.                 oLinksElement = oElement
  270.             }
  271.             showContentForContextElement(oElement,oLinksElement)
  272.         }
  273.         //elements with LINK className are <a> tags
  274.         colElements = document.getElementsByTagName("a")
  275.         for (var i = 0; i != colElements.length; i++)
  276.         {
  277.             oElement = colElements[i]
  278.             showContentForContextElement(oElement,oLinksElement)
  279.         }
  280.     }
  281. }
  282. function hideContentForContextElement(oElement)
  283. {
  284.     if ( (isContextElement(oElement)) || (isContextRelatedElement(oElement)) )
  285.     {
  286.         setStylePropertyByElement( oElement, 'display', 'none' ) // hide the element
  287.     }
  288. }
  289.  
  290. function hideContextContent()
  291. {
  292.     // Hide all elements that have context
  293.     var oElement
  294.     
  295.     if (isIE4)
  296.     {
  297.         for (var i = 0; i != document.all.length; i++)
  298.         {
  299.             oElement = document.all[i]
  300.             hideContentForContextElement(oElement)
  301.         }
  302.     }
  303.     else if (isNav6)
  304.     {
  305.         var colElements
  306.         //elements with INSTRUCTIONS, MORE_INFO, LINKS className are <div> tags
  307.         colElements = document.getElementsByTagName("div")
  308.         for (var i = 0; i != colElements.length; i++)
  309.         {
  310.             oElement = colElements[i]
  311.             hideContentForContextElement(oElement)
  312.         }
  313.         //elements with LINK className are <a> tags
  314.         colElements = document.getElementsByTagName("a")
  315.         for (var i = 0; i != colElements.length; i++)
  316.         {
  317.             oElement = colElements[i]
  318.             hideContentForContextElement(oElement)
  319.         }
  320.     }
  321. }
  322.  
  323. function toggleTips( strTipsID, strTipsImageID )
  324. {
  325.     var oTipsImageElement = getElementById( strTipsImageID )
  326.     
  327.     if (isIE4 || isNav6)
  328.     {
  329.         if ( getStylePropertyById( strTipsID,'display')=='none' )
  330.         {
  331.             setStylePropertyById( strTipsID, 'display', 'block' ) //show the Tips
  332.             if (oTipsImageElement != null)
  333.             {
  334.                 //show the down arrow
  335.                 oTipsImageElement.src = g_arrArrowImages[1]
  336.             }
  337.         }
  338.         else
  339.         {
  340.             setStylePropertyById( strTipsID, 'display', 'none' ) //hide the Tips
  341.             if (oTipsImageElement != null)
  342.             {
  343.                 //show the right arrow
  344.                 oTipsImageElement.src = g_arrArrowImages[0]
  345.             }
  346.         }
  347.     }
  348.     else
  349.     {}    //so Nav4 won't return error
  350. }
  351.  
  352. function takeMeThere( strURL, strWindowName )
  353. {
  354.     window.open( strURL, strWindowName )
  355. }
  356.  
  357. function toggleALTTOCImg( element, strEvent )
  358. {
  359.     // redirect to the ti function
  360.     ti( element, strEvent )
  361. }
  362.  
  363. function ti( element, strEvent )
  364. {
  365.     var oElement;
  366.     oElement = getElementObject( element );
  367.     
  368.     if (oElement != null)
  369.     {
  370.         var strSrc = oElement.src;
  371.         var intIndex = strSrc.lastIndexOf("/");
  372.         var strSrcRoot = "";
  373.         var strImgName = strSrc;
  374.         var strNewImgName;
  375.         if (intIndex >= 0) 
  376.         {
  377.             strSrcRoot = strSrc.substring(0,intIndex+1);
  378.             strImgName = strSrc.substring(intIndex+1,strSrc.length);
  379.         }
  380.         strImgName = strImgName.substring(0,strImgName.length - 4);
  381.         switch (strImgName)
  382.         {
  383.             case "question_icon":
  384.                 strNewImgName = 'question_icon_hover';
  385.                 break;
  386.             case "question_icon_hover":
  387.                 strNewImgName = 'question_icon';
  388.                 break;
  389.             case "widget_plus":
  390.                 if ( strEvent == 'r')
  391.                     strNewImgName = 'widget_plus_hvr';
  392.                 else if ( strEvent == 't')
  393.                     strNewImgName = 'widget_plus';
  394.                 else
  395.                     strNewImgName = 'widget_minus';
  396.                 break;
  397.             case "widget_plus_hvr":
  398.                 if ( strEvent == 't')
  399.                     strNewImgName = 'widget_plus';
  400.                 else
  401.                     strNewImgName = 'widget_minus';
  402.                 break;
  403.             case "widget_minus":
  404.                 if ( strEvent == 'r')
  405.                     strNewImgName = 'widget_minus_hvr';
  406.                 else if ( strEvent == 't')
  407.                     strNewImgName = 'widget_minus';
  408.                 else
  409.                     strNewImgName = 'widget_plus';
  410.                 break;
  411.             case "widget_minus_hvr":
  412.                 if ( strEvent == 't')
  413.                     strNewImgName = 'widget_minus';
  414.                 else
  415.                     strNewImgName = 'widget_plus';
  416.                 break;
  417.         }
  418.         oElement.src = strSrcRoot + strNewImgName + '.gif';
  419.     }
  420. }
  421.  
  422. /**********************************************************************
  423.     Generic Cross Browser Code
  424. **********************************************************************/
  425.  
  426. function setBrowser()
  427. {
  428.     //Simple browser sniffer
  429.     
  430.     if (document.all)
  431.     {
  432.         isIE4 = true
  433.     }
  434.     else if (document.layers)
  435.     {
  436.         isNav4 = true
  437.     }
  438.     else if (document.getElementById)
  439.     {
  440.         isNav6 = true //also true for IE5.5
  441.     }
  442. }
  443.  
  444. setBrowser(); // determine which browser we are using
  445.  
  446. function blur( oElement )
  447. {
  448.     oElement.blur()
  449. }
  450.  
  451. function existsForm( name )
  452. {
  453.     if ( typeof document.forms[name] == "object" )
  454.         return true
  455.     else
  456.         return false
  457. }
  458. function getElementById( strId )
  459. {
  460.     if (isNav6)
  461.     {
  462.         return document.getElementById( strId );
  463.     }
  464.     else if (isIE4)
  465.     {
  466.         return document.all[strId]
  467.     }
  468.     else
  469.     {
  470.         return null
  471.     }
  472. }
  473. function getElementObject( element )
  474. {
  475.     var oElement = null;
  476.     
  477.     // get the element
  478.     if (typeof element == "object")
  479.     {
  480.         oElement = element;
  481.     }
  482.     else if (typeof element == "string")
  483.     {
  484.         oElement = getElementById( element );
  485.     }
  486.     return oElement;    
  487. }
  488. function getStyleBySelector( selector )
  489. {
  490.     if (!isNav6)
  491.     {
  492.         return null;
  493.     }
  494.     var sheetList = document.styleSheets;
  495.     var ruleList;
  496.     var i, j;
  497.  
  498.     /* look through stylesheets in reverse order that
  499.        they appear in the document */
  500.     for (i=sheetList.length-1; i >= 0; i--)
  501.     {
  502.         ruleList = sheetList[i].cssRules;
  503.         for (j=0; j<ruleList.length; j++)
  504.         {
  505.             if (ruleList[j].type == CSSRule.STYLE_RULE && ruleList[j].selectorText == selector)
  506.             {
  507.                 return ruleList[j].style;
  508.             }   
  509.         }
  510.     }
  511.     return null;
  512. }
  513. function getStylePropertyById( strId, strProperty )
  514. {
  515.     if (isNav6)
  516.     {
  517.         var styleObject = document.getElementById( strId );
  518.         if (styleObject != null)
  519.         {
  520.             styleObject = styleObject.style;
  521.             if (styleObject[strProperty])
  522.             {
  523.                 return styleObject[ strProperty ];
  524.             }
  525.         }
  526.         styleObject = getStyleBySelector( "#" + strId );
  527.         return (styleObject != null) ?
  528.             styleObject[strProperty] :
  529.             null;
  530.     }
  531.     else if (isIE4)
  532.     {
  533.         return document.all[strId].style[strProperty];
  534.     }
  535.     else
  536.     {
  537.         return ""
  538.     }
  539. }
  540. function setStylePropertyById( strId, strProperty, strValue )
  541. {
  542.     if (isNav6)
  543.     {
  544.         var styleObject = document.getElementById( strId );
  545.         if (styleObject != null)
  546.         {
  547.             styleObject = styleObject.style;
  548.             styleObject[ strProperty ] = strValue;
  549.         }
  550.     }
  551.     else if (isIE4)
  552.     {
  553.         if (document.all[strId] != null)
  554.             document.all[strId].style[strProperty] = strValue;
  555.     }
  556.     else
  557.     {}    //so Nav4 won't return error
  558. }
  559. function setStylePropertyByElement( oElement, strProperty, strValue )
  560. {
  561.     if (isNav6)
  562.     {
  563.         var styleObject = oElement;
  564.         if (styleObject != null)
  565.         {
  566.             styleObject = styleObject.style;
  567.             styleObject[ strProperty ] = strValue;
  568.         }
  569.     }
  570.     else if (isIE4)
  571.     {
  572.         if (oElement != null)
  573.             oElement.style[strProperty] = strValue;
  574.     }
  575.     else
  576.     {}    //so Nav4 won't return error
  577. }
  578. function toggleElementDisplay( element, strStyle )
  579. {
  580.     // strStyle = (none,block,inline)
  581.     var strID
  582.     
  583.     //get the element id
  584.     if (typeof element == "object")
  585.     {
  586.         strID = element.id    
  587.     }
  588.     else if (typeof element == "string")
  589.     {
  590.         strID = element
  591.     }
  592.     
  593.     if ((strID != "") && (strID != null))
  594.     {
  595.         if (isIE4 || isNav6)
  596.         {
  597.             if ( getStylePropertyById( strID,'display')=='none' )
  598.             {
  599.                 setStylePropertyById( strID, 'display', strStyle ) //show the element
  600.             }
  601.             else
  602.             {
  603.                 setStylePropertyById( strID, 'display', 'none' ) //hide the element
  604.             }
  605.         }
  606.     }
  607. }
  608. function toggleImg( element, strImg1, strImg2 )
  609. {
  610.     var oElement;
  611.     oElement = getElementObject( element );
  612.     
  613.     if (oElement != null)
  614.     {
  615.         var strSrc = oElement.src;
  616.         if ( strSrc.indexOf(strImg1) > -1 )
  617.         {
  618.             oElement.src = strImg2;
  619.         }
  620.         else
  621.         {
  622.             oElement.src = strImg1;
  623.         }
  624.     }
  625. }
  626. function changeImg( element, strImg )
  627. {
  628.     var oElement;
  629.     oElement = getElementObject( element );
  630.     
  631.     if (oElement != null)
  632.     {
  633.         var strSrc = oElement.src;
  634.             oElement.src = strImg;
  635.     }
  636. }
  637.  
  638. /**********************************************************************
  639.     End Generic Cross-Browser Code
  640. **********************************************************************/
  641.  
  642.  
  643.